/**
 * @description 路由拦截状态管理，目前两种模式：all模式与intelligence模式，其中partialRoutes是菜单暂未使用
 */
import { defineStore } from 'pinia'
import type { themesState, themeConfigState } from '@/types/stores/theme'
import { getThemeConfirg } from '@/common/theme'

export const themesStore = defineStore('theme', {
  state: (): themesState => ({
    themeConfig: getThemeConfirg('default'),
    isDark: false,
  }),
  getters: {
    getThemeType: (state) => state.themeConfig.type,
    getThemeConfig: (state) => state.themeConfig,
    getIsDark: (state) => state.isDark,
    getThemeOverrides: (state) => state.themeConfig.naive,
    getAnimation: (state) => state.themeConfig.animation,
    getNavTwoWidth: (state) => state.themeConfig.menu.navtwo.width,
    getTopNavIsClose: (state) => state.themeConfig.menu.navtop.isClose,
  },
  actions: {
    /**
     * @description 设置默认值
     * @param themeConfig
     * */
    setConfirmTheme(themeConfig: themeConfigState) {
      this.themeConfig = themeConfig
      if (themeConfig.dart) {
        this.toggleDarkMode(true)
      } else {
        this.toggleDarkMode(false)
      }
    },
    /**
     * @description 切换主题
     * */
    toggleDarkMode(status: boolean) {
      this.isDark = status
      document.documentElement.setAttribute('mode', this.isDark ? 'dark' : 'light')
    },
  },
})
